package org.test.thread;

public class TortoiseRabbitRace implements Runnable {

    private String winner=null;

    @Override
    public void run() {

        for (int i = 1; i < 300 && winner==null; i++) {
            if(Thread.currentThread().getName().equals("兔子")){
                i+=9;
                if (i%60==0){
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        System.out.println(e.getMessage());
                    }
                }
            }
            System.out.println(Thread.currentThread().getName()+"到达了"+i+"处...");
        }
        if(winner==null){
            setWinner(Thread.currentThread().getName());
        }
    }

    public void setWinner(String winner) {
        this.winner = winner;
        System.out.println(Thread.currentThread().getName()+"获得了冠军!");
    }

    public static void main(String[] args) {
        TortoiseRabbitRace race=new TortoiseRabbitRace();
        new Thread(race,"兔子").start();
        new Thread(race,"乌龟").start();

    }
}
